package com.imooc.reader.management.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imooc.reader.management.dto.ResponseDTO;
import com.imooc.reader.management.entity.Member;
import com.imooc.reader.management.service.MemberService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/members")
public class MemberController {
    @Resource
    private MemberService memberService;
    @GetMapping("")
    public ResponseDTO list(Integer page , Integer rows , String mobile){
        if(page == null){
            page = 1;
        }
        if(rows == null){
            rows = 10;
        }
        IPage<Member> p = memberService.selectByMobile(new Page(page, rows), mobile);
        return new ResponseDTO().put("list", p.getRecords()).put("count", p.getTotal());
    }
    @DeleteMapping("/{memberId}")
    public ResponseDTO deleteUser(@PathVariable("memberId") Long memberId){
        Member member = memberService.deleteMember(memberId);
        return new ResponseDTO().put("member", member);
    }
}
